<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>JWChat - Chat</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <script src="shared.js"></script>
    <script src="browsercheck.js"></script>
    <script src="emoticons.js"></script>
    <script src="switchStyle.js"></script>
    <script src="statusLed.js"></script>
    <script src="xmlextras.js"></script>
    <script src="JSJaCPacket.js"></script>
    <script>
      <!--
var user;
var srcW;
var cFrame;

var scrollHeight=0;
function putMsgHTML(msg,mtime,user,usercolor,err) {
  var msgHTML = '';
  
  msg = msgFormat(msg);
  
  msgHTML += "<div title='@ "+mtime+"'><span class=time>["+mtime+"] </span>";
	if (err) {
		msgHTML += "<span style='color:red;'>";
  } else if (msg.match(/^\/me /)) {
    msg = msg.replace(/^\/me /,"<span style=\"color:green;font-weight:bold;\" class=msgnick>*&nbsp;"+user+"</span> ");
  } else {
    msgHTML += "<span style=\"color:"+usercolor+";\" class=msgnick>&lt;" + user + "&gt;</span>";
  }
  msgHTML += "&nbsp;" + msg;
	if (err)
		msgHTML += '</span>';
	msgHTML += "</div>";

	var auto_scroll = false;
	if (cFrame.body.scrollTop+cFrame.body.clientHeight >= cFrame.body.scrollHeight) // scrollbar at bottom
		auto_scroll = true;

  cFrame.body.innerHTML += msgHTML;

	if (auto_scroll)
		chat.scrollTo(0,cFrame.body.scrollHeight);
}

function popMsgs() {
  while (user.chatmsgs.length>0) {
    var msg;
    if (is.ie5||is.op) {
      msg = user.chatmsgs[0];
      user.chatmsgs = user.chatmsgs.slice(1,user.chatmsgs.length);
    } else
      msg = user.chatmsgs.shift();

		// calc date
		var now;
		if (msg.jwcTimestamp)
			now = msg.jwcTimestamp;
		else
			now = new Date();

		var mtime = (now.getHours()<10)? "0" + now.getHours() : now.getHours();
		mtime += ":";
		mtime += (now.getMinutes()<10)? "0" + now.getMinutes() : now.getMinutes();
		mtime += ":";
		mtime += (now.getSeconds()<10)? "0" + now.getSeconds() : now.getSeconds();

  
    putMsgHTML(msg.getBody(),mtime,user.name,"red");
  }
  if (jwcMain.focusWindows)	{
	  window.focus();
	  document.forms.chatform.msgbox.focus(); 
	}
  if (user.lastsrc != null && user.messages.length == 0) {
    var images = srcW.roster.getUserIcons(user.jid);
    for (var i=0; i<images.length; i++)
      images[i].src = user.lastsrc;
    user.lastsrc = null;
    if (srcW.roster.usersHidden && user.status == 'unavailable') // remove user from roster if not available any more 
      srcW.roster.print();
  }
}

function openUserInfo() {
	return jwcMain.openUserInfo(user.jid);
}

function openUserHistory() {
	return jwcMain.openUserHistory(user.jid);
}

function updateUserPresence() {
	//	var user = srcW.roster.getUserByJID(jid);	
	document.getElementById('user_name').innerHTML = user.name;
	//var img = document.images['statusLed'];
	//img.src = eval(user.status + "Led").src;
}

var jwcMain;
function init() {
  getArgs();
  
  jid = passedArgs['jid'];
  
  if (opener.top.roster) {
    srcW = opener.top;
    if (srcW.srcW)
      jwcMain = srcW.srcW;
    else
      jwcMain = srcW;
  } else {
    alert("error starting chat");
    window.close();
  }

  cFrame = chat.document;
  user = srcW.roster.getUserByJID(jid);
  document.title = "Chat with "+user.name;
	document.getElementById('user_name').innerHTML = user.name;
	updateUserPresence();

  popMsgs();
  displayTimestamp();
}

function displayTimestamp() {
  var tstyle;
  if (is.ie) {
    tstyle = cFrame.styleSheets('timestampstyle');
    tstyle.disabled = jwcMain.timestamps;
  } else {
    tstyle = cFrame.getElementById("timestampstyle");
    tstyle.sheet.disabled = jwcMain.timestamps;
  }
}

function submitClicked() {
	var body = document.forms[0].elements["msgbox"].value;
	if (body == '') // don't send empty message
		return true;

	var aMessage = new JSJaCMessage();
	aMessage.setType('chat');
	aMessage.setTo(user.jid);
	aMessage.setBody(body);

	jwcMain.con.send(aMessage);

	// store message - [TODO]
	if (jwcMain.enableLog && typeof(jwcMain.loghost) != 'undefined') {
		var aIQ = new JSJaCIQ();
		aIQ.setType('set');
		aIQ.setTo(jwcMain.loghost);
		var aNode = aIQ.getNode().appendChild(aIQ.getDoc().createElement('archive'));
		aNode.setAttribute('xmlns','http://jabber.org/protocol/archive');
		aNode.appendChild(aMessage.getNode().cloneNode(true));
		if (typeof(window.cid) != 'undefined') {
			aNode.setAttribute('cid',user.chatW.cid);
			jwcMain.con.send(aIQ);
		} else {
			storeCID = jwcMain.storeCID;
			jwcMain.con.send(aIQ,storeCID,user.jid);
		}
	}

	// insert into chat window
	var now = new Date();

	var mtime = (now.getHours()<10)? "0" + now.getHours() : now.getHours();
	mtime += ":";
	mtime += (now.getMinutes()<10)? "0" + now.getMinutes() : now.getMinutes();
	mtime += ":";
	mtime += (now.getSeconds()<10)? "0" + now.getSeconds() : now.getSeconds();
	putMsgHTML(body,mtime,srcW.roster.nick,"blue");

	// add message to our message history
	jwcMain.addtoHistory(body);
	document.forms["chatform"].msgbox.value=''; // empty box
	document.forms["chatform"].msgbox.focus(); // set focus back on input field
	
	return false;
}
			
var group_open = new Image();
group_open.src = 'images/group_open.gif';
var group_close = new Image();
group_close.src = 'images/group_close.gif';
var msgbox_toggled = false;
function toggle_msgbox(el) {
	if (msgbox_toggled) {
		document.getElementById('msgbox').style.height = '1.4em';
		document.getElementById('chat').style.height = '100%';
		//document.getElementById('submitbutton').style.display = 'none';
		el.src = group_close.src;
	} else {
		document.getElementById('msgbox').style.height = '4.2em';
		document.getElementById('chat').style.height = '99%';
		//document.getElementById('submitbutton').style.display = '';
		el.src = group_open.src;
	}
	msgbox_toggled = !msgbox_toggled;
}

function msgboxKeyPressed(el,e) {
	var keycode;
	if (window.event) { e  = window.event; keycode = window.event.keyCode; }
	else if (e) keycode = e.which;
	else return true;
	
	switch (keycode) {
	case 13:
		if (e.shiftKey) {
			if (!msgbox_toggled)
				toggle_msgbox(document.getElementById('toggle_icon'));
		} else
			return submitClicked();
		break;
	}
	return true;
}

function msgboxKeyDown(el,e) {
	var keycode;
	if (window.event) { e  = window.event; keycode = window.event.keyCode; }
	else if (e) keycode = e.which;
	else return true;

	switch (keycode) {
	case 38:				// shift+up
		if (e.ctrlKey) {
			el.value = jwcMain.getHistory('up', el.value);
			el.focus(); el.select();
		}
		break;
	case 40:				// shift+down 
		if (e.ctrlKey) {
			el.value = jwcMain.getHistory('down', el.value);
			el.focus(); el.select();
		}
		break;
	case 76:
		if (e.ctrlKey) {   // ctrl+l
			chat.document.body.innerHTML = '';
			return false;
		}
		break;
	case 27:
		window.close();
		break;
	}
	return true;
}

function cleanUp() {
	if (typeof(window.cid) != 'undefined') {
		var aIQ = new JSJaCIQ();
		aIQ.setType('set');
		aIQ.setTo(jwcMain.loghost);
		var aNode= aIQ.getNode().appendChild(aIQ.getDoc().createElement('done'));
		aNode.setAttribute('xmlns','http://jabber.org/protocol/archive');
		aNode.setAttribute('cid',window.cid);
		jwcMain.con.syncSend(aIQ.clone());
	}
}

onload = init;
onunload = cleanUp;
      //-->
    </script>
  </head>
  <body bgcolor="#DEEFCE">
  <table id="table1" style="height: 435px" height="455" cellSpacing="0" cellPadding="0" width="580" align="center" border="0">
	<tr>
		<td id="LeftContent" vAlign="top" width="156" style="font-family: Tahoma; font-size: 9pt">
		<table id="table2" style="height: 435px" height="100%" cellSpacing="0" cellPadding="0" width="156" border="0">
			<tr>
				<td id="td_01" height="62" style="font-family: Tahoma; font-size: 9pt">
				<img height="62" src="./LR/greenness/1.jpg" width="156"></td>
			</tr>
			<tr>
				<td id="td_02" style="font-family: Tahoma; font-size: 9pt; background: url('./LR/greenness/2.gif')" vAlign="top" align="middle">

				</td>
			</tr>
			<tr>
				<td id="td_copyright" height="73" style="font-family: Tahoma; font-size: 9pt">
				<img height="73" src="./LR/greenness/3_cn.jpg" width="156" border="0" usemap="#Map"></td>
			</tr>
		</table>
		</td>
		<td vAlign="top" width="18" style="font-family: Tahoma; font-size: 9pt">
		<table id="table3" style="height: 435px" cellSpacing="0" cellPadding="0" width="18" border="0">
			<tr>
				<td id="td_03" height="48" style="font-family: Tahoma; font-size: 9pt">
				<img height="48" src="./LR/greenness/4.jpg" width="18"></td>
			</tr>
			<tr>
				<td id="td_04" style="height: 331px; font-family: Tahoma; font-size: 9pt; background: url('./LR/greenness/10.gif')">
				<a title onClick="f5();return false;" href="./LR/chat.aspx?from=LRT22822636#">
				<img height="47" src="./LR/greenness/13-1.gif" width="9" border="0"></a></td>
			</tr>
			<tr>
				<td id="td_05" height="56" style="font-family: Tahoma; font-size: 9pt">
				<img height="56" src="./LR/greenness/6.jpg" width="18"></td>
			</tr>
		</table>
		</td>
		<td id="td_06" vAlign="top" width="406" style="font-family: Tahoma; font-size: 9pt">
		<table id="table4" style="height: 435px" cellSpacing="0" cellPadding="0" width="406" border="0">
			<tr>
				<td id="td_07" style="font-family: Tahoma; font-size: 9pt; background: url('./LR/greenness/8.jpg')" vAlign="top" height="48">
				<table cellSpacing="0" cellPadding="0" border="0" id="table5">
					<tr>
						<td height="29" style="font-family: Tahoma; font-size: 9pt">　</td>
					</tr>
					<tr>
						<td id="td_prompt1" style="font-size: 9pt; color: #066723; font-family: Tahoma">
						<span id="user_name">正在和您进行对话..</td>
					</tr>
				</table>
				</td>
				<td id="td_08" width="20" style="font-family: Tahoma; font-size: 9pt">
				<img height="48" src="./LR/greenness/5.jpg" width="20"></td>
			</tr>
			<tr>
				<td vAlign="top" style="font-family: Tahoma; font-size: 9pt">
				<!--iframe id="chatwordsFrame" style="height: 226px; border-style: none" name="I1" frameBorder="1" width="386" src="./LR/im.aspx">
				</iframe-->
				<iframe src="chat_iframe.html" id="chat" name="chat" scrolling="yes" style="width:100%;height:100%;overflow:hidden"></iframe>
				</td>
				<td id="td_13" style="font-family: Tahoma; font-size: 9pt; background: url('./LR/greenness/11.gif')">&nbsp;
				</td>
			</tr>
			<tr id="uploadobj" style="display: none" height="72">
				<td style="font-family: Tahoma; font-size: 9pt">
				<!--iframe id="uploadFrame" style="height: 72px; border-style: none" name="I2" frameBorder="0" width="386" height="72" src="./LR/im.aspx"></iframe-->
				<!--iframe src="chat_iframe.html" id="chat" name="chat" scrolling="yes" style="width:100%;height:100%;"></iframe!-->
				</td>
				<td id="td_17" style="font-family: Tahoma; font-size: 9pt; background: url('./LR/greenness/11.gif')">&nbsp;
				</td>
			</tr>
			<tr id="uploadobj1" style="display: none" height="31">
				<td style="font-family: Tahoma; font-size: 9pt">
				<table cellSpacing="0" cellPadding="0" width="100%" border="0" id="table6">
					<tr>
						<td style="font-family: Tahoma; font-size: 9pt">
						正在发送文件，请稍等...</td>
						<td id="progressPmt" align="middle" style="font-family: Tahoma; font-size: 9pt">　</td>
						<td align="right" style="font-family: Tahoma; font-size: 9pt">
						<a onClick="f31(false);return false;" href="#">取消</a>&nbsp;&nbsp;</td>
					</tr>
				</table>
				<div style="font-size: 1px; width: 100%; height: 15px; border: 1px solid #006000; margin-left: 3px; margin-right: 3px; margin-bottom: 1px; padding: 1px">
					<div id="progressBar" style="width: 0%; height: 100%; background-color: #00a000" align="center">
　</div>
				</div>
				</td>
				<td id="td_18" style="font-family: Tahoma; font-size: 9pt; background: url('./LR/greenness/11.gif')">&nbsp;
				</td>
			</tr>
			<tr>
				<td id="td_14" style="font-size: 9pt; font-family: Tahoma; background: url('./LR/greenness/12.jpg')" height="25">
				<table height="25" cellSpacing="0" cellPadding="0" border="0" id="table7">
					<tr>
						<td style="font-family: Tahoma; font-size: 9pt">
						<a title="选择表情" onClick="SelSmile();return false;" href="./LR/chat.aspx?from=LRT22822636#">
						<img height="21" src="./LR/greenness/smile.gif" width="30" border="0"></a></td>
						<td width="2" style="font-family: Tahoma; font-size: 9pt">
						</td>
						<td style="font-family: Tahoma; font-size: 9pt">
						<a title="设置字体和样式" onClick="SetFont();return false;" href="./LR/chat.aspx?from=LRT22822636#">
						<img height="21" src="./LR/greenness/font.gif" width="30" border="0"></a></td>
						<td width="2" style="font-family: Tahoma; font-size: 9pt">
						</td>
						<td style="font-family: Tahoma; font-size: 9pt">
						<a title="发送文件" onClick="f27();return false;" href="./LR/chat.aspx?from=LRT22822636#">
						<img height="21" src="./LR/greenness/file.gif" width="30" border="0"></a></td>
						<td width="2" style="font-family: Tahoma; font-size: 9pt">
						</td>
						<td style="font-family: Tahoma; font-size: 9pt">
						<a title="免费电话" onClick="Freecall();return false;" href="./LR/chat.aspx?from=LRT22822636#">
						<img height="21" src="./LR/greenness/freecall.gif" width="30" border="0"></a></td>
						<td width="2" style="font-family: Tahoma; font-size: 9pt">
						</td>
						<td style="font-family: Tahoma; font-size: 9pt">
						<a title="保存对话记录" onClick="f23();return false;" href="./LR/chat.aspx?from=LRT22822636#">
						<img height="21" src="./LR/greenness/save.gif" width="30" border="0"></a></td>
						<td width="2" style="font-family: Tahoma; font-size: 9pt">
						</td>
						<td style="font-family: Tahoma; font-size: 9pt">
						<a title="打印对话记录" onClick="f24();return false;" href="./LR/chat.aspx?from=LRT22822636#">
						<img height="21" src="./LR/greenness/print.gif" width="30" border="0"></a></td>
						<td width="2" style="font-family: Tahoma; font-size: 9pt">
						</td>
						<td style="font-family: Tahoma; font-size: 9pt">
						<a title="发送留言" target="_blank" href="./LR/SendNote2.aspx?siteid=LRT22822636&imgint=4&lng=cn&cid=6330931741378125008697&p=http%3a%2f%2fwww.zgcmr.com%2f&e=">
						<img height="21" src="./LR/greenness/note.gif" width="30" border="0"></a></td>
						<td width="2" style="font-family: Tahoma; font-size: 9pt">
						</td>
					</tr>
				</table>
				</td>
				<td id="td_12" style="font-family: Tahoma; font-size: 9pt; background: url('./LR/greenness/11.gif')">&nbsp;
				</td>
			</tr>
			<form name="chatform" style="border:0px;margin:0px;padding:0px;">
			<tr>
				<td height="80" style="font-family: Tahoma; font-size: 9pt">
				<!--iframe id="FreeTextBox1_editor" onblur="editblur();" style="border-style: none" onfocus="editfocus();" name="I3" frameBorder="1" width="386" height="80" src="./LR/im.aspx">
				</iframe-->
				<textarea id="msgbox" wrap="virtual" style="width:100%;height:1.4em;" onKeyPress="return msgboxKeyPressed(this,event);" onKeyDown="return msgboxKeyDown(this,event);"></textarea>
				
				</td>
				<td id="td_11" style="font-family: Tahoma; font-size: 9pt; background: url('./LR/greenness/11.gif')">&nbsp;
				</td>
			</tr>
			  </form>
			<tr>
				<td id="td_09" style="font-family: Tahoma; font-size: 9pt; background: url('./LR/greenness/9.jpg')" vAlign="top" height="56">
				<table id="table8" cellSpacing="0" cellPadding="0" width="386" border="0">
					<tr>
						<td colSpan="3" height="5" style="font-family: Tahoma; font-size: 9pt">
						</td>
					</tr>
					<tr>
						<td id="td_prompt2" style="font-size: 9pt; color: #066723; font-family: Tahoma">
						发送快捷键:Enter</td>
						<td id="td_15" width="70" style="font-family: Tahoma; font-size: 9pt">
						<a title="发送讯息" onClick="User_Send();return false;" href="./LR/chat.aspx?from=LRT22822636#">
						<img height="21" src="./LR/greenness/send_cn.gif" width="70" border="0"></a></td>
						<td id="td_16" width="9" style="font-family: Tahoma; font-size: 9pt">
						<a title="设置发送讯息快捷键" onClick="SwitchShortCut();return false;" href="./LR/chat.aspx?from=LRT22822636#">
						<img height="21" src="./LR/greenness/15.gif" width="9" border="0"></a></td>
					</tr>
				</table>
				</td>
				<td id="td_10" style="font-family: Tahoma; font-size: 9pt">
				<img height="56" src="./LR/greenness/7.jpg" width="20"></td>
			</tr>
		</table>
		</td>
	</tr>
</table>  

  </body>
</html>
